package com.example.testfile;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

	EditText add;
	EditText deletefilename;
	Button addfile;
	Button addsdfile;
	Button deletefile;
	Button deletesdfile;
	TextView text;
	static Context context;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		context = getApplicationContext();

		add = (EditText) findViewById(R.id.edit_add);
		deletefilename = (EditText) findViewById(R.id.edit_deletefile);
		addfile = (Button) findViewById(R.id.bt_addfile);
		addsdfile = (Button) findViewById(R.id.bt_addsdfile);
		deletefile = (Button) findViewById(R.id.bt_deletefile);
		deletesdfile = (Button) findViewById(R.id.bt_deleteSDfile);
		text = (TextView) findViewById(R.id.text_context);

		addfile.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				try {

					FileHelper.writeFile("test.txt", add.getText().toString());

					text.setText(FileHelper.readFile("test.txt"));

				} catch (Exception e) {
					e.printStackTrace();
				}

			}
		});

		addsdfile.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				try {
					FileHelper.writeSDFile("mnt/sdcard/test.txt", add.getText()
							.toString());

					text.setText(FileHelper.readSDFile("mnt/sdcard/test.txt"));
				} catch (Exception e) {
					e.printStackTrace();
				}

			}
		});

		deletefile.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				try {
					FileHelper.deleteFile(deletefilename.getText().toString());

					text.setText("");
				} catch (Exception e) {
					e.printStackTrace();
				}

			}
		});
		
		deletesdfile.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				try {
					FileHelper.deletesdFile(deletefilename.getText().toString());

					text.setText("");
				} catch (Exception e) {
					e.printStackTrace();
				}

			}
		});

	}
}
